/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DragBarTest.java
 *
 * Created on May 12, 2009, 11:25:40 AM
 */
package DragBarPanelPackage;

import java.awt.Dimension;
import java.awt.Graphics;

/**
 *
 * @author Heather
 */
public class DragBarTest extends javax.swing.JApplet
{

  /** Initializes the applet DragBarTest */
  public void init()
  {
    try
    {
      java.awt.EventQueue.invokeAndWait(new Runnable()
      {

        public void run()
        {
          setSize(600, 500);
          initComponents();
          dbPanel.setSize(testPanel.getSize());
          testPanel.add(dbPanel);
        }
      });
    } catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }

  /** This method is called from within the init() method to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    resize = new javax.swing.JButton();
    testPanel = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    removeButton = new javax.swing.JButton();
    movetest = new javax.swing.JToggleButton();
    jButton3 = new javax.swing.JButton();
    textField = new javax.swing.JTextField();
    scaleText = new javax.swing.JTextField();

    setBackground(new java.awt.Color(204, 204, 255));
    getContentPane().setLayout(null);

    resize.setText("Toggle Size");
    resize.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        resizeActionPerformed(evt);
      }
    });
    getContentPane().add(resize);
    resize.setBounds(10, 390, 120, 60);

    javax.swing.GroupLayout testPanelLayout = new javax.swing.GroupLayout(testPanel);
    testPanel.setLayout(testPanelLayout);
    testPanelLayout.setHorizontalGroup(
      testPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 610, Short.MAX_VALUE)
    );
    testPanelLayout.setVerticalGroup(
      testPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 378, Short.MAX_VALUE)
    );

    getContentPane().add(testPanel);
    testPanel.setBounds(10, 10, 610, 378);

    jButton1.setText("clear");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    getContentPane().add(jButton1);
    jButton1.setBounds(10, 450, 120, 60);

    jButton2.setText("Add another button");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    getContentPane().add(jButton2);
    jButton2.setBounds(130, 390, 150, 60);

    removeButton.setText("remove a button");
    removeButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        removeButtonActionPerformed(evt);
      }
    });
    getContentPane().add(removeButton);
    removeButton.setBounds(130, 450, 150, 60);

    movetest.setText("move to");
    movetest.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        movetestActionPerformed(evt);
      }
    });
    getContentPane().add(movetest);
    movetest.setBounds(450, 450, 170, 60);

    jButton3.setText("set scale");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton3ActionPerformed(evt);
      }
    });
    getContentPane().add(jButton3);
    jButton3.setBounds(280, 450, 170, 60);
    getContentPane().add(textField);
    textField.setBounds(280, 400, 170, 40);
    getContentPane().add(scaleText);
    scaleText.setBounds(450, 400, 170, 40);
  }// </editor-fold>//GEN-END:initComponents


    private void resizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resizeActionPerformed
      Dimension oldSize = testPanel.getSize();

      if (isBig)
      {
        testPanel.setSize(SMALL_SIZE, oldSize.height);
        testPanel.setPreferredSize(new Dimension(SMALL_SIZE, oldSize.height));
        dbPanel.setSize(testPanel.getSize());
      } else
      {
        testPanel.setSize(BIG_SIZE, oldSize.height);
        testPanel.setPreferredSize(new Dimension(BIG_SIZE, oldSize.height));
        dbPanel.setSize(testPanel.getSize());
      }

      isBig = !isBig;
    }//GEN-LAST:event_resizeActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
      // TODO add your handling code here:
      dbPanel.clearBG();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
      // TODO add your handling code here:
      dbPanel.addNewButton("Another Button");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_removeButtonActionPerformed
    {//GEN-HEADEREND:event_removeButtonActionPerformed
      // TODO add your handling code here:
      int i = dbPanel.getButtons().size() - 1;
      dbPanel.removeAButton(i);
    }//GEN-LAST:event_removeButtonActionPerformed

    private void movetestActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_movetestActionPerformed
    {//GEN-HEADEREND:event_movetestActionPerformed
      double value = Double.parseDouble(scaleText.getText());
      dbPanel.setButtonValueAndMove(dbPanel.getButtons().get(0), value);
    }//GEN-LAST:event_movetestActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton3ActionPerformed
    {//GEN-HEADEREND:event_jButton3ActionPerformed
      double newScale = Double.parseDouble(textField.getText());
      
      dbPanel.setScale(newScale);
    }//GEN-LAST:event_jButton3ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JButton jButton3;
  private javax.swing.JToggleButton movetest;
  private javax.swing.JButton removeButton;
  private javax.swing.JButton resize;
  private javax.swing.JTextField scaleText;
  private javax.swing.JPanel testPanel;
  private javax.swing.JTextField textField;
  // End of variables declaration//GEN-END:variables
  private DragBarPanel dbPanel = new DragBarPanel(4);
  private boolean isBig = false;
  private int SMALL_SIZE = 358;
  private int BIG_SIZE = 590;
  private boolean flag = false;
  private double scale = 0;

  /*
  public void update(Graphics g)
  {
    System.out.println("I'm called");
    super.update(g);
    dbPanel.setSize(getSize());
  }*/
}
